 //1.公用样式
 require('../../assets/css/index.js')
 //当前页面样式
 require('./kkstest.less')
    //2.公用js
let dom=require('../../utils/dom.js');
let http=require('../../utils/http.js');
let https=require('../../utils/https.js');
dom.ready(function(){
    dom.ft('exercise');

    let recommendCourse=dom.getById('.recommendCourse')
    let course=dom.getById('.course')
    let listcourse=dom.getById('.listcourse')

    
    
    
    https.get('/api/train/courseList',function(res) {
      if (res.errno==0) {
        let listHtml='';
        let newHtml='';
            // console.log(res.data);
            // <a href="${v.courseId}">
              res.data.map(function(v,i){
                if (i<=1) {
                  newHtml+=`
                    
                      <div class="img" data-id='${v.courseId}'>
                      <img  alt="" src='${https.BASE_URL+v.imgurl}'>
                        <div class="texts">
                            <div class="txtTop">${v.name}</div>
                            <p>${v.desc}</p>
                        </div>
                      </div>
                  `
                }else{
                  listHtml+=`

                  
                    <div class="img" data-id='${v.courseId}'>
                    <img  alt="" src='${https.BASE_URL+v.imgurl}'>
                      <div class="texts">
                          <div class="txtTop">${v.name}</div>
                          <p>${v.desc}</p>
                      </div>
                    </div>
                 
                  `
                }
             })
            //  推荐课程
            recommendCourse.innerHTML=newHtml
            // 课程
            listcourse.innerHTML=listHtml
      }
      
    })
    recommendCourse.addEventListener('click',function(event){
      console.log(event.target.parentNode);
      let boxdata=event.target.parentNode
      let val=boxdata.dataset['id']
      // console.log(event);
      
      // console.log(val);
      
      window.location.href=`?${val}`
    })
    listcourse.addEventListener('click',function(event){
      console.log(event.target.parentNode);
      let boxdata=event.target.parentNode
      let val=boxdata.dataset['id']
      // console.log(val);
      window.location.href=`?${val}`
      
    })
   



    
})